// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 

package com.yoyo.lib.net;

import android.os.AsyncTask;
import com.yoyo.lib.AppException;
import com.yoyo.lib.net.itf.ICallback;
import com.yoyo.lib.net.itf.IProgressListener;
import com.yoyo.lib.net.itf.IRequestListener;
import com.yoyo.lib.utilities.Trace;
import java.net.HttpURLConnection;

// Referenced classes of package com.stay.lib.net:
//            RequestInformation, HttpUrlUtil

public class HttpRequestTask extends AsyncTask {

    private String operationName;
    private RequestInformation request;

    public HttpRequestTask(RequestInformation requestinformation) {
        request = requestinformation;
    }

    @Override
    protected Object doInBackground(Object... parames) {
        try {
            Object object = null;
            if (request.mRequestListener != null) {
                request.mRequestListener.onBeforeDoingBackground();
            }
            HttpURLConnection httpurlconnection = HttpUrlUtil.execute(request);
            if (request.requestCallback != null) {
                if (request.mProgressChangeListener != null) {
                    IProgressListener task = new IProgressListener() {

                        public void progressChanged(int status, int percent, String operationName) {
                            if (operationName != null)
                                HttpRequestTask.this.operationName = operationName;
                            if (percent != -1) {
                                HttpRequestTask httprequesttask = HttpRequestTask.this;
                                Integer ainteger[] = new Integer[2];
                                ainteger[0] = Integer.valueOf(status);
                                ainteger[1] = Integer.valueOf(percent);
                                httprequesttask.publishProgress(ainteger);
                            }
                        }
                    };
                    object = request.requestCallback.handleConnection(httpurlconnection, task);
                } else {
                    object = request.requestCallback.handleConnection(httpurlconnection);
                }

                if (request.mRequestListener != null) {
                    return request.mRequestListener.onAfterDoingBackground(object);
                }

                return object;
            } else {
                return null;
            }
        } catch (AppException e) {
            e.printStackTrace();
            return e;
        }

    }

    protected void onCancelled() {
        super.onCancelled();
        Trace.d("onCancelled");
        if (request.mRequestListener != null) {
            request.mRequestListener.onCancelled();
        }
    }

    protected void onPostExecute(Object result) {
        super.onPostExecute(result);
        if (request.requestCallback != null) {
            if (result instanceof AppException) {
                request.requestCallback.onFailure(( AppException ) result);
            } else {
                request.requestCallback.onCallback(result);
            }
        }
        if (request.mRequestListener != null) {
            request.mRequestListener.onPostExecute();
        }
    }

    protected void onPreExecute() {
        super.onPreExecute();
        if (request.mRequestListener != null) {
            request.mRequestListener.onPreExecute();
        }
    }

    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        if (request.mProgressChangeListener != null) {
            request.mProgressChangeListener.progressChanged(values[0].intValue(), values[1].intValue(),
                    operationName);
        }
    }

    protected void onProgressUpdate(Object... objects) {
        onProgressUpdate(( Integer[] ) objects);
    }

    /*
        static String access$002(HttpRequestTask httprequesttask, String s)
        {
            httprequesttask.operationName = s;
            return s;
        }

    */

}
